package com.longge;

public class GiveGem {

    public int giveGem(int[] gem, int[][] operations) {
        for (int[] operation : operations) {
            int i = gem[operation[0]];
            gem[operation[0]] -= i / 2;
            gem[operation[1]] += i / 2;
        }

        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;

        for (int i : gem) {
            max = Math.max(max, i);
            min = Math.min(min, i);
        }
        return max - min;

    }

}
